package com.kui.springcloud.controller;

import com.kui.springcloud.model.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Base64;
import java.util.List;

/**
 * Created by 风 on 2021/5/24.
 */
@RequestMapping("/dept")
@RestController
public class DeptController {
    @Autowired
    private RestTemplate restTemplate;
//    private static String BASE_URL = "http://localhost:8001/dept";
    private static String BASE_URL = "http://SPRINGCLOUD-PROVIDER/dept";
    @PostMapping("/add")
    public boolean addDept(Dept dept){
        return restTemplate.postForObject(BASE_URL + "/add", dept, Boolean.class);
    }
    @GetMapping("/{id}")
    public Dept queryById(@PathVariable Long id){
        return restTemplate.getForObject(BASE_URL + "/"+id, Dept.class);
    }
    @GetMapping("/list")
    public List<Dept> findAll(){
        return restTemplate.getForObject(BASE_URL + "/list", List.class);
    }
}
